<template lang="pug">
  .clearfix
    Modal(
      v-model="isShowOrganizationUnitTreeModal"
      title="选择要分享的对象"
      class-name="vertical-center-modal"
    )
      .h360.overflow-y-scroll
        Tree(:data="treeData" show-checkbox multiple check-directly @on-check-change="treeCheckChange")

      .clearfix(slot="footer")
        Button(type="text" @click="cancel") 取消
        Button(type="primary" @click="handleSubmit") 确定
</template>

<script>
import { PolicySupportApi } from '@/api/PolicySupport.api.js'
export default {
  name: '',

  props: {
  },

  data () {
    return {
      isShowOrganizationUnitTreeModal: false,
      treeData: [],
      selectNode: null
    }
  },

  watch: {
  },

  mounted () {
  },

  methods: {
    // 获取组织架构
    async getOrganizationUnitTree () {
      let res = await PolicySupportApi.getOrganizationUnitTree()
      console.log('获取组织架构 res: ', res)
      this.treeData = res.data
    },

    cancel () {
      this.isShowOrganizationUnitTreeModal = false
    },

    handleSubmit () {
      if (this.selectNode) {
        this.isShowOrganizationUnitTreeModal = false
        this.$emit('handleSubmit', this.selectNode)
      } else {
        this.$Message.error({
          content: '请选择要分享的对象',
          duration: 10,
          closable: true
        })
      }
    },

    treeCheckChange (value) {
      var tempArr = []
      value.map(item => {
        if (item.type === 'Employee') {
          tempArr.push(item.id)
        }
      })
      this.selectNode = tempArr
      console.log('被勾选的节点有this.selectNode: ', this.selectNode)
    }
  }
}
</script>

<style lang="less" scope>
</style>
